<template>
  <div class="page-box">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model="state.dataForm.stationName" placeholder="杆塔名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <!--      <el-form-item>-->
      <!--        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item>-->
      <!--        <el-button v-if="state.hasPermission('KxImageSettings:kximagesettings:save')" type="primary"-->
      <!--                   @click="addOrUpdateHandle()">{{ $t("add") }}-->
      <!--        </el-button>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item>-->
      <!--        <el-button v-if="state.hasPermission('KxImageSettings:kximagesettings:delete')" type="danger"-->
      <!--                   @click="state.deleteHandle()">{{ $t("deleteBatch") }}-->
      <!--        </el-button>-->
      <!--      </el-form-item>-->
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border
              @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <!--      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>-->
      <!--      <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>-->
      <!--      <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>-->
      <el-table-column prop="stationName" label="杆塔名称" header-align="center" align="center"></el-table-column>
      <!--      <el-table-column prop="frameNo" label="帧序列号" header-align="center" align="center"></el-table-column>-->
      <!--      <el-table-column prop="flag" label="" header-align="center" align="center"></el-table-column>-->
      <el-table-column prop="channelNo" label="通道号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="minute1" label="间隔时间" header-align="center" align="center">
        <template #default="scope">
          {{ padStartTime(scope.row.hour1, scope.row.minute1) }}
        </template>
      </el-table-column>
      <el-table-column prop="hour2" label="工作时间" header-align="center" align="center">
        <template #default="scope">
          {{ padStartTime(scope.row.hour2, scope.row.minute2) }} -
          {{ padStartTime(scope.row.hour3, scope.row.minute3) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button type="primary" link @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
                   :total="state.total" layout="total, sizes, prev, pager, next, jumper"
                   @size-change="state.pageSizeChangeHandle"
                   @current-change="state.pageCurrentChangeHandle"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import {nextTick, reactive, ref, toRefs, watch} from "vue";
import AddOrUpdate from "./kximagesettings-add-or-update.vue";
import {Eleme} from "@element-plus/icons-vue";

const view = reactive({
  getDataListURL: "/KxImageSettings/kximagesettings/page",
  getDataListIsPage: true,
  exportURL: "/KxImageSettings/kximagesettings/export",
  deleteURL: "/KxImageSettings/kximagesettings",
  deleteIsBatch: true,
  dataForm: {
    stationName: ""
  }
});

const state = reactive({...useView(view), ...toRefs(view)});


const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(id);
  });
};

function padStartTime(hour: Number, minute: Number) {
  if (hour) {
    return hour.toString().padStart(2, '0') + ":" + minute.toString().padStart(2, '0');
  } else {
    return "00:00"
  }
}
</script>
